'use strict';

/**
 * 修改http内置服务
 */
angular.module('app').config(['$provide',function ($provide) {
    /**
     * 装饰HTTP服务
     * $delegate用于指代$http
     */
    $provide.decorator('$http',['$delegate', '$q',function ($delegate,$q) {
        var get = $delegate.get;
        $delegate.post = function (url,data,config) {
            var def = $q.defer();
            get(url).success(function (resp) {
                def.resolve(resp);
            }).error(function (err) {
                def.reject(err);
            });
            return {
                success:function (cb) {
                    def.promise.then(cb);
                },
                error:function (cb) {
                    def.promise.then(null,cb);
                }
            }
        };
        return $delegate;
    }]);
}]);





